package org.jxc.web.action;

import java.util.List;

import org.jxc.domain.ProductType;
import org.jxc.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.team4.web.action.GenericAction;

@Controller
@Scope("prototype")
public class ProductTypeAction extends GenericAction<ProductType> {

	private static final long serialVersionUID = -4867867482994497216L;

	@Autowired
	private ProductTypeService productTypeService;
	private List<ProductType> productTypeList;
	private ProductType productType;
	private String productTypeId;

	/**
	 * 类别树
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listTree() throws Exception {
		productTypeList = productTypeService.findAllProductType();
		return SUCCESS;
	}

	public String listPagination() throws Exception {
		page = productTypeService.listPagination(page, productTypeId);
		return SUCCESS;
	}

	/**
	 * 预新建
	 * 
	 * @return
	 * @throws Exception
	 */
	public String toSave() throws Exception {
		productTypeList = productTypeService.findAllProductType();
		return SUCCESS;
	}

	/**
	 * 新建
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception {
		productTypeService.saveProductType(productType);
		return SUCCESS;
	}

	/**
	 * 预修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String toUpdate() throws Exception {
		productType = productTypeService.findById(productTypeId);
		productTypeList = productTypeService.findAllProductType();
		return SUCCESS;
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String update() throws Exception {
		productTypeService.updateProductType(productType);
		return SUCCESS;
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception {
		for (String str : idList) {
			try {
				productTypeService.deleteProductType(str);
			} catch (Exception e) {
				continue;
			}
		}
		return SUCCESS;
	}

	public List<ProductType> getProductTypeList() {
		return productTypeList;
	}

	public void setProductTypeList(List<ProductType> productTypeList) {
		this.productTypeList = productTypeList;
	}

	public ProductType getProductType() {
		return productType;
	}

	public void setProductType(ProductType productType) {
		this.productType = productType;
	}

	public String getProductTypeId() {
		return productTypeId;
	}

	public void setProductTypeId(String productTypeId) {
		this.productTypeId = productTypeId;
	}
}